package scjp.threads.guide.exercises.ninedottwo;

public class SyncBlockCodeExercise extends Thread {


    private StringBuffer stringBuffer;

    public SyncBlockCodeExercise(StringBuffer stringBuffer) {

        this.stringBuffer = stringBuffer;
    }

    @Override
    public void run() {

        synchronized (stringBuffer) {

            for (int i = 0; i < 100; i++) {

                System.out.print(stringBuffer);
                stringBuffer.append(1);

            }


        }


    }


    public static void main(String[] args) {


        StringBuffer stringBuffer = new StringBuffer("A");

        SyncBlockCodeExercise syncBlockCodeExercise1 = new SyncBlockCodeExercise(stringBuffer);
        SyncBlockCodeExercise syncBlockCodeExercise2 = new SyncBlockCodeExercise(stringBuffer);
        SyncBlockCodeExercise syncBlockCodeExercise3 = new SyncBlockCodeExercise(stringBuffer);

        syncBlockCodeExercise1.start();
        syncBlockCodeExercise2.start();
        syncBlockCodeExercise3.start();

    }
}
